/**
 * 
 */
package com.newworld.crush;


import io.yunba.android.manager.YunBaManager;

import java.io.File;

import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.IMqttToken;
import org.litepal.LitePalApplication;

import android.content.Context;
import android.util.Log;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.pgyersdk.crash.PgyCrashManager;

/**
 * @author Administrator
 * 
 */
public class CrashApplication extends LitePalApplication {

	private Context mcontext = this;
	private final static String TAG = "CrashApplication";

	@Override
	public void onCreate() {
		super.onCreate();
		//蒲公英初始化
		PgyCrashManager.register(this);
		// 初始化云巴
		YunBaManager.start(getApplicationContext());

		YunBaManager.subscribe(getApplicationContext(),
				new String[] { "systermMessage"}, new IMqttActionListener() {

					@Override
					public void onSuccess(IMqttToken arg0) {
						Log.d(TAG, "Subscribe topic succeed");
					}

					@Override
					public void onFailure(IMqttToken arg0, Throwable arg1) {
						Log.d(TAG, "Subscribe topic failed");
					}
				});
		LitePalApplication.getContext();
		CrashHandler crashHandler = CrashHandler.getInstance();
		crashHandler.init(getApplicationContext());
		DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
				.cacheInMemory().cacheOnDisc().build();

		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
				this).defaultDisplayImageOptions(defaultOptions)
				.threadPriority(Thread.NORM_PRIORITY - 2)
				.denyCacheImageMultipleSizesInMemory()
				.discCacheFileNameGenerator(new Md5FileNameGenerator())
				.tasksProcessingOrder(QueueProcessingType.LIFO).build();
		ImageLoader.getInstance().init(config);
		File parent1 = new File("/sdcard/NewWorld_APP2_Photo/");
		if (!parent1.exists()) {
			parent1.mkdirs();
		}
		File parent2 = new File("/sdcard/NewWorld_APP2_Voice/");
		if (!parent2.exists()) {
			parent2.mkdirs();
		}
	}
}
